//
//  YYETopicRecordTableViewCell.m
//  YuYingEDU
//
//  Created by 胡波 on 2018/1/5.
//  Copyright © 2018年 胡波. All rights reserved.
//

#import "YYETopicRecordTableViewCell.h"

@interface YYETopicRecordTableViewCell ()

@property (nonatomic,strong) UIImageView *headerIV;
@property (nonatomic,strong) UILabel *nameLabel;
@property (nonatomic,strong) UILabel *timeLabel;
@property (nonatomic,strong) UILabel *progressLabel;
@property (nonatomic,strong) UIButton *btn;
@property (nonatomic,strong) UIView *lineView;

@end

@implementation YYETopicRecordTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
//        self.contentView.backgroundColor = GeneralBackColor;
        
        self.nameLabel = [[UILabel alloc]init];
        self.nameLabel.font = [UIFont systemFontOfSize:14];
        self.nameLabel.textColor = [UIColor blackColor];
        [self.contentView addSubview:self.nameLabel];
        
        self.headerIV = [[UIImageView alloc]init];
        [self.contentView addSubview:self.headerIV];
        
        self.timeLabel = [[UILabel alloc]init];
        self.timeLabel.textColor = LineColor;
        self.timeLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.timeLabel];
        
        self.progressLabel = [[UILabel alloc]init];
        self.progressLabel.textColor = LineColor;
        self.progressLabel.font = [UIFont systemFontOfSize:10];
        [self.contentView addSubview:self.progressLabel];
        
        self.btn = [[UIButton alloc]init];
        [self.contentView addSubview:self.btn];
        self.btn.userInteractionEnabled = NO;
        
        self.lineView = [[UIView alloc]init];
        self.lineView.backgroundColor = LightLineColor;
        [self.contentView addSubview:self.lineView];
        
        self.nameLabel.text = @"英语轻松过四级小秘籍（一）";
        self.timeLabel.text = @"英语";
        self.progressLabel.text = @"未到进度";

    }
    return self;
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    

    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.left).offset(19);
        make.top.equalTo(self.contentView.top).offset(24);
    }];
    
    [self.headerIV makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.right).offset(14);
        make.centerY.equalTo(self.nameLabel.centerY);
        make.size.equalTo(CGSizeMake(12, 14));
    }];

    [self.timeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.left);
        make.top.equalTo(self.nameLabel.bottom).offset(18);
    }];

    [self.btn makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.right).offset(-21);
        make.centerY.equalTo(self.contentView.centerY);
        make.size.equalTo(CGSizeMake(50, 50));

    }];

    [self.progressLabel makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.right).offset(-26);
        make.centerY.equalTo(self.contentView.centerY);

    }];
    
    [self.lineView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.left).offset(15);
        make.right.equalTo(self.contentView.right).offset(-15);
        make.bottom.equalTo(self.contentView.bottom);
        make.height.equalTo(0.5);
    }];
    
}

// "process": 1, //进度(0未达到进度 1开始答题 2继续答题 3查看答题
// "type": 2, // 1是习题 2是考试
- (void)setModel:(YYEWrongRecordModel *)model
{
    _model = model;
    
    self.nameLabel.text = model.name;
    self.timeLabel.text = model.title;
    
    if (model.process.integerValue == 0) {
        
        self.btn.hidden = YES;
        self.progressLabel.hidden = NO;

    } else {
        
        self.btn.hidden = NO;
        self.progressLabel.hidden = YES;
        
        if (model.process.integerValue == 1) {
            
            [self.btn setImage:[UIImage imageNamed:@"icon_kaishi"] forState:UIControlStateNormal];

        } else if (model.process.integerValue == 2) {
            
            [self.btn setImage:[UIImage imageNamed:@"icon_jixu"] forState:UIControlStateNormal];

        } else {
            [self.btn setImage:[UIImage imageNamed:@"icon_chakan"] forState:UIControlStateNormal];

        }
    }
        
    if (model.type.integerValue == 1) {
        
        [self.headerIV setImage:[UIImage imageNamed:@"xiti"]];

        
    } else {
        [self.headerIV setImage:[UIImage imageNamed:@"shijuangng"]];

        
    }
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
